package com.fcscs.cservice.client.main.reservation;

import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.Label;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.form.AdapterField;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.fcscs.core.gwt.common.CoreConstants;
import com.fcscs.core.gwt.common.FormSubmitListener;
import com.fcscs.core.gwt.common.ui.BaseFormDialog;
import com.fcscs.core.gwt.common.ui.FcsFormPanel;
import com.fcscs.core.gwt.common.ui.FcsFields.FormButton;
import com.fcscs.cservice.client.common.CServiceConstants;
import com.fcscs.cservice.domain.model.ReservationView;
import com.fcscs.share.gwt.common.ShareGWTConstants;

public class BaggageDialog extends BaseFormDialog<ReservationView> {
	private MyFormPanel formPanel;
	private static BaggageDialog INSTANCE;
	
	public static BaggageDialog getInstance(){
		if(null == INSTANCE){
			INSTANCE = new BaggageDialog();
		}
		INSTANCE.setHeading(CServiceConstants.CSERVICE_CONSTANTS.baggageInfo());
		return INSTANCE;
	}
	
	private BaggageDialog(){
		formPanel = new MyFormPanel(null);
		formPanel.setId("BaggageDialog_formPanel");
		add(formPanel);
		setSize(360, 205);
	}
	
	private class MyFormPanel extends FcsFormPanel<ReservationView>{
		private Label guestNameLabel;
		private AdapterField guestNameAF;
		
		private Label baggageNOLabel;
		private AdapterField baggageNOAF;
		
		private Label numberOfBaggageLabel;
		private AdapterField numberOfBaggageAF;
		
		private Label locationStoreLabel;
		private AdapterField locationStoreAF;
		
		private FormButton okButton;

		protected MyFormPanel(FormSubmitListener<ReservationView> l) {
			super(l);
			setHeaderVisible(false);
			
			LayoutContainer lc = new LayoutContainer();
			lc.setId("BaggageDialog_lc");
			
			FormLayout layout = new FormLayout();
			layout.setLabelAlign(LabelAlign.LEFT);
			layout.setLabelWidth(160);
			layout.setDefaultWidth(160);
			lc.setLayout(layout);
			
			guestNameLabel = new Label();
			guestNameLabel.setId("BaggageDialog_guestNameLabel");
			
			guestNameAF = new AdapterField(guestNameLabel);
			guestNameAF.setId("BaggageDialog_guestNameAF");
			guestNameAF.setFieldLabel(ShareGWTConstants.SHARE_GWT_CONSTANTS.guestName());
			lc.add(guestNameAF);
			
			baggageNOLabel = new Label();
			baggageNOLabel.setId("BaggageDialog_baggageNOLabel");
			
			baggageNOAF = new AdapterField(baggageNOLabel);
			baggageNOAF.setId("BaggageDialog_baggageNOAF");
			baggageNOAF.setFieldLabel(CServiceConstants.CSERVICE_CONSTANTS.baggageNo());
			lc.add(baggageNOAF);
			
			numberOfBaggageLabel = new Label();
			numberOfBaggageLabel.setId("BaggageDialog_numberOfBaggageLabel");
			
			numberOfBaggageAF = new AdapterField(numberOfBaggageLabel);
			numberOfBaggageAF.setId("BaggageDialog_numberOfBaggageAF");
			numberOfBaggageAF.setFieldLabel(CServiceConstants.CSERVICE_CONSTANTS.numberOfBaggage());
			lc.add(numberOfBaggageAF);
			
			locationStoreLabel = new Label();
			locationStoreLabel.setId("BaggageDialog_locationStoreLabel");
			
			locationStoreAF = new AdapterField(locationStoreLabel);
			locationStoreAF.setId("BaggageDialog_locationStoreAF");
			locationStoreAF.setFieldLabel(CServiceConstants.CSERVICE_CONSTANTS.locationStored());
			lc.add(locationStoreAF);
			
			add(lc);
			
			okButton = new FormButton(CoreConstants.CORE_CONSTANTS.ok());
			okButton.setId("BaggageDialog_okButton");
			okButton.addSelectionListener(new SelectionListener<ButtonEvent>(){
				@Override
				public void componentSelected(ButtonEvent ce) {
					BaggageDialog.this.hide();
				}
			});
			
			getButtonBar().add(okButton);
		}

		@Override
		public void updateForm(ReservationView entity) {
			guestNameLabel.setText(entity.getGuestFirstName() + "," + entity.getGuestLastName());
			baggageNOLabel.setText(entity.getBaggageNumber());
			numberOfBaggageLabel.setText(entity.getNumberOfBaggage()+"");
			locationStoreLabel.setText(entity.getBaggageLocation());
		}

		@Override
		public void populateEntity(ReservationView entity) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void setFocus() {
			// TODO Auto-generated method stub
			
		}
		
	}
	
	@Override
	protected FcsFormPanel<ReservationView> getFormPanel() {
		return formPanel;
	}

}
